package com.itholmes.controller;

import java.io.IOException;
import java.sql.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.itholmes.pojo.Emp;
import com.itholmes.pojo.Result;
import com.itholmes.service.EmpServiceOneSelect;
import com.itholmes.utils.CookieUtils;
import com.itholmes.utils.ServletForJsonUtil;

@WebServlet("/empOneSelect")
public class EmpOneSelect extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		int user_id = CookieUtils.cookiesEaxm(req);
		if(user_id == -1) {
			resp.getWriter().write("登录失效或者已经过期，请重新回到登录页面进行登录。");
		}
		
		Emp emp = ServletForJsonUtil.jsonToObj(req, Emp.class);
		int empno = emp.getEmpno();
		
		EmpServiceOneSelect oneSelect = new EmpServiceOneSelect();
		Emp emp2 = oneSelect.getOneSelect(empno);
		
		Result result = new Result();
		result.setData(emp2);
		
		GsonBuilder gsonBuilder = new GsonBuilder();
		Gson gson = gsonBuilder.setDateFormat("yyyy-MM-dd").create();
		String str = gson.toJson(result);
		
		resp.getWriter().write(str);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doGet(req, resp);
	}
}
